<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page import="com.fjrcloud.entity.Formalities" contentType="text/html;charset=UTF-8" %>
<%@ page import="com.fjrcloud.entity.Land" contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>合算</title>

    <link rel="shortcut icon" href="favicon.ico">
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
    <link href="../plugins/jquery-ui-1.12.1/jquery-ui.min.css" rel="stylesheet">

    <style>
        table {
            margin-left: auto;
            margin-right: auto;
        }

        table td {
            width: 12.5%;
            height: 4rem;
            line-height: 20px;
            text-align: center;
            padding-left: 10px;
            padding-right: 10px;
        }

        table, tr, td {
            border: solid 1px;
        }

        table thead tr {
            border-color: rgba(255, 255, 255, 0)
        }

        table td.title {
            background: #e7eaec;
        }

        table tbody tr[data-id]:hover {
            background-color: #edf5fa;
            cursor: pointer;
        }

        table tbody tr td.nested-panel {
            padding: 0;
        }

        table tbody tr td table {
            width: 100%;
        }

        .nested-panel table,
        .nested-panel tr,
        .nested-panel td {
            border: 0;
        }

        .nested-panel td {
            border-top: solid 1px;
            border-right: solid 1px;
        }

        .nested-panel thead td {
            border-top: 0;
        }

        .nested-panel tr td:last-child {
            border-right: 0;
        }

        .ui-autocomplete {
            z-index: 999999999;
        }

        .checkbox label, .radio label {
            padding-left: 0;
        }

        .input-group[disabled] .input-group-addon {
            background-color: #eee;
            cursor: not-allowed;
        }

        @media print {
            .not-print {
                display: none;
            }
        }
    </style>
</head>

<c:set var="clearing" value="<%=Land.clearing %>"/>
<c:set var="building" value="<%=Land.building %>"/>

<c:set var="without" value="<%=Formalities.without %>"/>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInUp">
        <div class="row">
            <div class="col-sm-12">

                <div class="ibox">
                    <div class="ibox-title not-print">
                        <h5>补偿费计算</h5>
                        <div class="ibox-tools">
                            <button class="btn btn-primary btn-xs errorArea" disabled>选房误差面积</button>
                            <button class="btn btn-primary btn-xs buyArea" disabled>照顾购买</button>
                            <button class="btn btn-primary btn-xs homestead" disabled>宅基地</button>
                            <button class="btn btn-primary btn-xs storefront" disabled>店面补偿</button>
                            <button class="btn btn-primary btn-xs disposable" disabled>一次性搬迁补助</button>
                            <button class="btn btn-primary btn-xs time-reward" disabled>按时奖励</button>
                            <button class="btn btn-primary btn-xs relocation-transition" disabled>过渡安置</button>
                            <button class="btn btn-primary btn-xs open"><i class="fa fa-user"></i></button>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12">
                                <table id="content">
                                    <thead>
                                        <tr>
                                            <th colspan="7" style="text-align: center;"><h1>房屋征收补偿费计算表</h1></th>
                                        </tr>
                                    </thead>
                                    <tbody class="info-total">
                                        <tr>
                                            <td>被征收人</td>
                                            <td class="master"></td>
                                            <td>认定年限</td>
                                            <td></td>
                                            <td colspan="3">土地使用情况</td>
                                        </tr>
                                        <tr>
                                            <td colspan="4" rowspan="2" class="housing-total">被征收房屋情况（单层 ㎡，共 ㎡）</td>
                                            <td>认定补偿安置的建筑占地</td>
                                            <td>认定不予补偿安置的建筑占地</td>
                                            <td>埕地空地</td>
                                        </tr>
                                    </tbody>
                                    <thead>
                                        <tr>
                                            <td colspan="4" class="title">房屋情况</td>
                                            <td colspan="3" class="title">装修情况</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td colspan="4" class="nested-panel housing-structure">
                                                <table>
                                                    <thead><tr><td>结构等级</td><td>成新</td><td>面积</td></tr></thead>
                                                    <tbody><tr><td></td><td></td><td></td></tr></tbody>
                                                </table>
                                            </td>
                                            <td colspan="3" class="nested-panel housing-decorate">
                                                <table>
                                                    <thead><tr><td>装修等级</td><td>成新</td><td>面积</td></tr></thead>
                                                    <tbody><tr><td></td><td></td><td></td></tr></tbody>
                                                </table>
                                            </td>
                                        </tr>
                                    </tbody>
                                    <tbody>
                                        <tr>
                                            <td>安置情况</td>
                                            <td colspan="6" class="resettlement-class"></td>
                                        </tr>
                                    </tbody>
                                    <thead>
                                        <tr>
                                            <td colspan="2">款项</td>
                                            <td>项目</td>
                                            <td>面积（㎡）</td>
                                            <td>单价（元/㎡）</td>
                                            <td>系数</td>
                                            <td>金额（元）</td>
                                        </tr>
                                    </thead>
                                    <tbody class="first-issue">
                                        <tr>
                                            <td class="merge-total" colspan="2" rowspan="3">先予发放的款项</td>
                                            <td class="merge-relocation">搬迁补助</td>
                                            <td></td>
                                            <td>${relocationPrice}</td>
                                            <td>1</td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td class="merge-total" colspan="2" style="display: none;">先予发放的款项</td>
                                            <td class="merge-temporary">临时过渡补助</td>
                                            <td></td>
                                            <td>${temporaryPrice}</td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td class="merge-total" colspan="2" style="display: none;">先予发放的款项</td>
                                            <td>低保户/五保户/孤寡老人</td>
                                            <td></td>
                                            <td>${difficultPrice}</td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                    </tbody>
                                    <tbody class="choose-room-settlement">
                                        <tr>
                                            <td>选房时结算</td>
                                            <td>选择货币补偿部分</td>
                                            <td>建筑占地补偿款</td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td>选房时结算</td>
                                            <td>选择货币补偿部分</td>
                                            <td>房屋重置价补偿</td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td>选房时结算</td>
                                            <td>选择货币补偿部分</td>
                                            <td>二次装修补偿</td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td>选房时结算</td>
                                            <td>产权调换</td>
                                            <td>二次装修补偿</td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="../js/jquery.min.js?v=2.1.4"></script>
    <script src="../js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <%--<script src="../js/content.js?v=1.0.0"></script>--%>
    <!-- iCheck -->
    <script src="../js/plugins/iCheck/icheck.min.js"></script>
    <script src="../js/plugins/layer/layer.min.js"></script>
    <script src="../js/plugins/jsKnob/jquery.knob.js"></script>
    <script src="../js/jquery.form.js"></script>
    <script src="../js/date.extension.js"></script>
    <script src="../js/business.js"></script>

    <script src="../plugins/jquery-ui-1.12.1/jquery-ui.min.js"></script>

    <script>
        var total = 0.0;
        var maxBuyArea = 0.0;

        var methods = business('${path}','${result_success}');

        function masterUpdate(master) {
            $('#content .master').text(master.name);
            $('#content .master').attr('data-id',master.id);
        }
        function housingOverviewUpdate(result) {
            $('#content .housing-total').text('被征收房屋情况（单层 '+result.monolayer+'㎡，共 '+result.total+'㎡）');
            $('#content .housing-total').attr('data-id',result.compensate);
        }
        function landOverviewUpdate(result) {
            $('#content .info-total .land-info').remove();
            $('#content .info-total').append('\
                    <tr class="land-info">\
                        <td>'+result.building.compensate+'</td>\
                        <td>'+(result.building.total - result.building.compensate)+'</td>\
                        <td>'+result.clearing+'</td>\
                    </tr>\
                ');
        }
        /**
         * 房屋结构等级表格
         * @param structure
         */
        function housingStructureInfoUpdate(structure) {
            var html = '';
            for(var key in structure){
                html += '\
                    <tr>\
                        <td>'+structure[key].level+'</td>\
                        <td>'+structure[key].intoNew+'</td>\
                        <td>'+structure[key].area+'</td>\
                    </tr>\
                ';
            }
            $('#content .housing-structure').html('\
                    <table>\
                        <thead><tr><td>结构等级</td><td>成新</td><td>面积</td></tr></thead>\
                        <tbody>'+html+'</tbody>\
                    </table>\
                ');
        }
        /**
         * 房屋装修等级表格
         * @param decorate
         */
        function housingDecorateInfoUpdate(decorate) {
            var html = '';
            for(var key in decorate){
                html += '\
                    <tr>\
                        <td>'+decorate[key].level+'</td>\
                        <td>'+decorate[key].intoNew+'</td>\
                        <td>'+decorate[key].area+'</td>\
                    </tr>\
                ';
            }
            $('#content .housing-decorate').html('\
                    <table>\
                        <thead><tr><td>装修等级</td><td>成新</td><td>面积</td></tr></thead>\
                        <tbody>'+html+'</tbody>\
                    </table>\
                ');
        }
        function resettlementOverviewUpdate(result) {
            $('#content .resettlement-class').text(result);
        }
        /**
         * 先予发放的款项
         */
        function resettlementInfoUpdate(result,compensate) {
            if($.isEmptyObject(result))
                return '';

            var el = $('#content .first-issue');

            el.html('');

            el.append('\
                    <tr>\
                        <td class="merge-total" colspan="2" style="display: none;">先予发放的款项</td>\
                        <td class="merge-relocation" style="display: none;">搬迁补助</td>\
                        <td>'+compensate+'</td>\
                        <td>${relocationPrice}</td>\
                        <td>1</td>\
                        <td>'+(compensate*${relocationPrice})+'</td>\
                    </tr>\
                ');
            total += compensate*${relocationPrice};

            if((compensate-result.currencyCompensateArea)>0){

                el.append('\
                        <tr>\
                            <td class="merge-total" colspan="2" style="display: none;">先予发放的款项</td>\
                            <td class="merge-relocation" style="display: none;">搬迁补助</td>\
                            <td>'+(compensate-result.currencyCompensateArea)+'</td>\
                            <td>${relocationPrice}</td>\
                            <td>1</td>\
                            <td>'+((compensate-result.currencyCompensateArea)*${relocationPrice})+'</td>\
                        </tr>\
                    ');

                total += (compensate-result.currencyCompensateArea)*${relocationPrice};
            }

            if(!result.arrange){
                if(result.currencyCompensateArea != 0 || result.existingCompensateArea != 0){
                    el.append('\
                        <tr>\
                            <td class="merge-total" colspan="2" style="display: none;">先予发放的款项</td>\
                            <td class="merge-temporary" style="display: none;">临时过渡补助</td>\
                            <td>'+(result.currencyCompensateArea+result.existingCompensateArea)+'</td>\
                            <td>${temporaryPrice}</td>\
                            <td>6</td>\
                            <td>'+(result.currencyCompensateArea*${temporaryPrice}*6)+'</td>\
                        </tr>\
                    ');

                    total += result.currencyCompensateArea*${temporaryPrice}*6;
                }
                if(result.firstPhaseCompensateArea != 0){
                    el.append('\
                        <tr>\
                            <td class="merge-total" colspan="2" style="display: none;">先予发放的款项</td>\
                            <td class="merge-temporary" style="display: none;">临时过渡补助</td>\
                            <td>'+(result.firstPhaseCompensateArea)+'</td>\
                            <td>${temporaryPrice}</td>\
                            <td>'+result.firstPhaseTimeLimit+'</td>\
                            <td>'+(result.firstPhaseCompensateArea*${temporaryPrice}*result.firstPhaseTimeLimit)+'</td>\
                        </tr>\
                    ');

                    total += result.firstPhaseCompensateArea*${temporaryPrice}*result.firstPhaseTimeLimit;
                }
                if(result.secondPhaseCompensateArea != 0){
                    el.append('\
                        <tr>\
                            <td class="merge-total" colspan="2" style="display: none;">先予发放的款项</td>\
                            <td class="merge-temporary" style="display: none;">临时过渡补助</td>\
                            <td>'+(result.secondPhaseCompensateArea)+'</td>\
                            <td>${temporaryPrice}</td>\
                            <td>'+result.secondPhaseTimeLimit+'</td>\
                            <td>'+(result.secondPhaseCompensateArea*${temporaryPrice}*result.secondPhaseTimeLimit)+'</td>\
                        </tr>\
                    ');

                    total += result.secondPhaseCompensateArea*${temporaryPrice}*result.secondPhaseTimeLimit;
                }
            }

        }
        function resettlementDifficultUpdate(master) {

            if(master.difficultFive || master.difficultLow || master.difficultOld){
                $('#content .first-issue').append('\
                    <tr class="difficult">\
                        <td class="merge-total" colspan="2" style="display: none;">先予发放的款项</td>\
                        <td>低保户/五保户/孤寡老人</td>\
                        <td>一次性</td>\
                        <td>${difficultPrice}</td>\
                        <td>1</td>\
                        <td>${difficultPrice}</td>\
                    </tr>\
                ');

                total += ${difficultPrice};
            }

        }

        function chooseHousingSettlementLand(result,currencyRatio,isReward) {

            var building = {admit:0.0,disown:0.0};
            var clearing = {admit:{},disown:0.0};

            $(result).each(function () {

                if(this.standard.type == 'building'){

                    if(this.standard.pattern){
                        var admint = this.area*this.standard.ratio/100.0;
                        building.admit += admint;
                        building.disown += this.area-admint;
                    }else{
                        building.disown += this.area;
                    }

                }else{

                    if(this.standard.pattern){
                        if(clearing.admit[this.standard.id] == undefined){
                            clearing.admit[this.standard.id] = {};
                            clearing.admit[this.standard.id].name = this.standard.name;
                            clearing.admit[this.standard.id].area = 0.0;

                            clearing.admit[this.standard.id].ratio = this.standard.ratio+'%';

                            clearing.admit[this.standard.id].result=0.0;
                        }

                        clearing.admit[this.standard.id].area += this.area;
                        clearing.admit[this.standard.id].result += this.area*${compensatePrice}*this.standard.ratio/100.0;
                    }else{
                        clearing.disown += this.area;
                    }

                }
            });

            for(var key in clearing.admit){
                var value = clearing.admit[key];
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="land" style="display: none;">土地补偿款</td>\
                                <td>'+value.name+'</td>\
                                <td>'+value.area+'</td>\
                                <td>${compensatePrice}</td>\
                                <td>'+value.ratio+'</td>\
                                <td>'+value.result+'</td>\
                            </tr>\
                            ');

                total += value.result;
            }
            $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="land" style="display: none;">土地补偿款</td>\
                                <td>未确权和未经市镇（街）两级清理收费</td>\
                                <td>'+clearing.disown+'</td>\
                                <td>${imposePrice}</td>\
                                <td></td>\
                                <td>'+(clearing.disown*${imposePrice})+'</td>\
                            </tr>\
                            ');

            total += clearing.disown*${imposePrice};

            $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="land" style="display: none;">土地补偿款</td>\
                                <td>认定可补偿部分建筑占地货币补偿</td>\
                                <td>'+building.admit+'</td>\
                                <td>${compensatePrice}</td>\
                                <td>'+currencyRatio+'</td>\
                                <td>'+(building.admit*${compensatePrice}*currencyRatio)+'</td>\
                            </tr>\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="land" style="display: none;">土地补偿款</td>\
                                <td>认定不予补偿部分建筑占地货币补偿</td>\
                                <td>'+building.disown+'</td>\
                                <td>${imposePrice}</td>\
                                <td></td>\
                                <td>'+(building.disown*${imposePrice})+'</td>\
                            </tr>\
                            ');
            total += (building.admit*${compensatePrice}*currencyRatio)+(building.disown*${imposePrice});

            $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="land" style="display: none;">土地补偿款</td>\
                                <td>埕地空地奖励</td>\
                                <td>'+clearing.disown+'</td>\
                                <td>${landRewardPrice}</td>\
                                <td></td>\
                                <td>'+(clearing.disown*${landRewardPrice})+'</td>\
                            </tr>\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="land" style="display: none;">土地补偿款</td>\
                                <td>认定不予补偿部分建筑占地奖励</td>\
                                <td>'+building.disown+'</td>\
                                <td>${landRewardPrice}</td>\
                                <td></td>\
                                <td>'+(building.disown*${landRewardPrice})+'</td>\
                            </tr>\
                            ');
            total += (clearing.disown*${landRewardPrice})+(building.disown*${landRewardPrice});

        }

        function chooseHousingSettlementHousingExchange(result) {
            $(result).each(function () {
                var area = this.compensate + this.notCompensate;
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="housing-exchange" style="display: none;">产权调换</td>\
                                <td class="housing-exchange-decorate" style="display: none;">二次专修补偿</td>\
                                <td>'+area+'</td>\
                                <td>'+this.decorateLevel.price+'</td>\
                                <td>'+this.decorateIntoNew.ratio+'%</td>\
                                <td>'+(area*this.decorateLevel.price*this.decorateIntoNew.ratio/100.0)+'</td>\
                            </tr>\
                            ');
                total += area*this.decorateLevel.price*this.decorateIntoNew.ratio/100.0;
            });
        }
        function chooseHousingSettlementCurrency(result) {

            var decorate = '';
            var structure = '';
            var disposable = '';

            $(result).each(function () {

                var area = this.compensate + this.notCompensate;
                if(this.landStandard.pattern){
                    structure += '\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="housing-currency" style="display: none;">货币补偿</td>\
                                <td class="housing-currency-structure" style="display: none;">房屋重置补偿</td>\
                                <td>'+area+'</td>\
                                <td>'+this.structureLevel.price+'</td>\
                                <td>'+this.structureIntoNew.ratio+'</td>\
                                <td>'+(area*this.structureLevel.price*this.structureIntoNew.ratio/100.0)+'</td>\
                            </tr>\
                            ';
                    total += (area*this.structureLevel.price*this.structureIntoNew.ratio/100.0);
                    decorate += '\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="housing-currency" style="display: none;">货币补偿</td>\
                                <td class="housing-currency-decorate" style="display: none;">二次专修补偿</td>\
                                <td>'+area+'</td>\
                                <td>'+this.decorateLevel.price+'</td>\
                                <td>'+this.decorateIntoNew.ratio+'</td>\
                                <td>'+(area*this.decorateLevel.price*this.decorateIntoNew.ratio/100.0)+'</td>\
                            </tr>\
                            ';
                    total += (area*this.decorateLevel.price*this.decorateIntoNew.ratio/100.0);
                }else{
                    disposable += '\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="housing-currency" style="display: none;">货币补偿</td>\
                                <td class="housing-currency-disposable" style="display: none;">一次搬迁补助</td>\
                                <td>'+this.area+'</td>\
                                <td>'+this.master.disposable+'</td>\
                                <td></td>\
                                <td>'+(this.area*this.master.disposable)+'</td>\
                            </tr>\
                            ';
                    total += (this.area*this.master.disposable);
                }
            });

            $('#content .choose-room-settlement').append(structure);
            $('#content .choose-room-settlement').append(decorate);
            $('#content .choose-room-settlement').append(disposable);
        }
        function chooseHousingSettlementReward(onTime,isArrange,compensate){
            if(onTime.signing){
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td colspan=2>按时签约奖励</td>\
                                <td>'+compensate+'</td>\
                                <td>${signingRewardPrice}</td>\
                                <td></td>\
                                <td>'+(compensate*${signingRewardPrice})+'</td>\
                            </tr>\
                            ');

                total += (compensate*${signingRewardPrice});
            }
            if(onTime.seal){
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td colspan=2>按时封房奖励</td>\
                                <td>'+compensate+'</td>\
                                <td>${sealRewardPrice}</td>\
                                <td></td>\
                                <td>'+(compensate*${sealRewardPrice})+'</td>\
                            </tr>\
                            ');

                total += (compensate*${sealRewardPrice});
            }
            if(!isArrange){
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td colspan=2>自行过渡奖励</td>\
                                <td>'+compensate+'</td>\
                                <td>${transitionRewardPrice}</td>\
                                <td></td>\
                                <td>'+(compensate*${transitionRewardPrice})+'</td>\
                            </tr>\
                            ');
                total += (compensate*${transitionRewardPrice});
            }
        }
        function chooseHousingSettlementNotExchangePriceDifference(result){

            var layer4 = 0.0;
            var layer5 = 0.0;
            var layer6 = 0.0;

            $(result).each(function () {
                if(this.landStandard.pattern){
                    if(this.layer <= 4){
                        layer4 += this.compensate;
                    }else if(this.layer == 5){
                        layer5 += this.compensate;
                    }else if(this.layer == 6){
                        layer6 += this.compensate;
                    }
                }
            });

            if(layer4 != 0){
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="not-exchange-price-difference" colspan=2 style="display: none;">放弃产权调换安置的补差</td>\
                                <td>'+layer4+'</td>\
                                <td>${layer4Price}</td>\
                                <td></td>\
                                <td>'+(layer4*${layer4Price})+'</td>\
                            </tr>');

                total += (layer4*${layer4Price});
            }
            if(layer5 != 0){
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="not-exchange-price-difference" colspan=2 style="display: none;">放弃产权调换安置的补差</td>\
                                <td>'+layer5+'</td>\
                                <td>${layer5Price}</td>\
                                <td></td>\
                                <td>'+(layer5*${layer5Price})+'</td>\
                            </tr>');

                total += (layer5*${layer5Price});
            }
            if(layer6 != 0){
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td class="not-exchange-price-difference" colspan=2 style="display: none;">放弃产权调换安置的补差</td>\
                                <td>'+layer6+'</td>\
                                <td>${layer6Price}</td>\
                                <td></td>\
                                <td>'+(layer6*${layer6Price})+'</td>\
                            </tr>\
                            ');
                total += (layer6*${layer6Price});
            }

        }
        function chooseHousingSettlementStorefront(result) {
            if(result != undefined && result.standard != undefined){
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td colspan=2>店面补偿</td>\
                                <td>'+result.area+'</td>\
                                <td>'+result.standard.price+'</td>\
                                <td></td>\
                                <td>'+(result.area*result.standard.price)+'</td>\
                            </tr>\
                            ');
                total += (result.area*result.standard.price);
            }
        }
        function chooseHousingSettlementAppendages(result) {

            var amount = 0.0;
            $(result).each(function () {
                amount += this.amount;
            });
            
            if(amount != 0){
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td colspan=2>附属物/其他</td>\
                                <td></td>\
                                <td></td>\
                                <td></td>\
                                <td>'+amount+'</td>\
                            </tr>\
                            ');

                total += amount;
            }
        }
        function chooseHousingSettlementStructureDifference(structure,layer,compensate,errorArea) {

            var price = 0.0;
            if(layer == 1){
                price = structure.layer1;
            }else if(layer == 2){
                price = structure.layer2;
            }else if(layer == 3){
                price = structure.layer3;
            }else if(layer == 4){
                price = structure.layer4;
            }else if(layer == 5){
                price = structure.layer5;
            }else if(layer > 5){
                price = structure.layer6;
            }

            var amount = compensate*price;
            if(amount > 0){
                $('#content .choose-room-settlement').append('\
                    <tr>\
                        <td class="choose" style="display: none;">选房时结算</td>\
                        <td colspan=2>房屋结构补差</td>\
                        <td>'+compensate+'</td>\
                        <td>'+price+'</td>\
                        <td></td>\
                        <td>'+amount+'</td>\
                    </tr>\
                ');
                total += amount;
            }
            if(errorArea != null && errorArea > 0){
                if(errorArea>7){
                    $('#content .choose-room-settlement').append('\
                        <tr>\
                            <td class="choose" style="display: none;">选房时结算</td>\
                            <td colspan=2 rowspan=2>选房面积误差</td>\
                            <td>7</td>\
                            <td>${errorAreaPriceBasicPrice}</td>\
                            <td></td>\
                            <td>'+(7*${errorAreaPriceBasicPrice})+'</td>\
                        </tr>\
                        <tr>\
                            <td class="choose" style="display: none;">选房时结算</td>\
                            <td>'+(errorArea-7)+'</td>\
                            <td>${errorAreaPriceSecondaryPrice}</td>\
                            <td></td>\
                            <td>'+((errorArea-7)*${errorAreaPriceSecondaryPrice})+'</td>\
                        </tr>\
                    ');
                    total += ((errorArea-7)*${errorAreaPriceSecondaryPrice})
                }else{
                    $('#content .choose-room-settlement').append('\
                        <tr>\
                            <td class="choose" style="display: none;">选房时结算</td>\
                            <td colspan=2>选房面积误差</td>\
                            <td>'+errorArea+'</td>\
                            <td>${errorAreaPriceBasicPrice}</td>\
                            <td></td>\
                            <td>'+(errorArea*errorAreaPriceBasicPrice)+'</td>\
                        </tr>\
                    ');
                    total += (errorArea*errorAreaPriceBasicPrice);
                }
            }

        }
        function chooseHousingSettlementBuyArea(resul) {

            if(resul != null){
                $('#content .choose-room-settlement').append('\
                            <tr>\
                                <td class="choose" style="display: none;">选房时结算</td>\
                                <td colspan=2>照顾购买面积</td>\
                                <td>'+resul+'</td>\
                                <td>-${takeCareOfBuyPrice}</td>\
                                <td></td>\
                                <td>'+(resul*${takeCareOfBuyPrice}*-1)+'</td>\
                            </tr>\
                            ');
                total += (resul*${takeCareOfBuyPrice}*-1);
            }
        }
        function equallyShared(result) {

            if(result == null)
                return;

            var value = result*0.1;
            if(value>10)
                value = 10;

            $('#content .choose-room-settlement').append('\
                        <tr>\
                            <td colspan=3>交房时结算的款项（公摊）</td>\
                            <td>'+value+'</td>\
                            <td>${equallySharedPrice}</td>\
                            <td></td>\
                            <td>'+(value*${equallySharedPrice})+'</td>\
                        </tr>\
                        ');

            total += (value*${equallySharedPrice});

        }
        function merge() {
            var firstIssue = $('#content .first-issue');

            firstIssue.find('.merge-total:first').show();
            firstIssue.find('.merge-total').attr("rowspan",firstIssue.find('.merge-total').length);

            firstIssue.find('.merge-relocation:first').show();
            firstIssue.find('.merge-relocation').attr("rowspan",firstIssue.find('.merge-relocation').length);

            firstIssue.find('.merge-temporary:first').show();
            firstIssue.find('.merge-temporary').attr("rowspan",firstIssue.find('.merge-temporary').length);

            var choose = $('#content .choose-room-settlement');

            choose.find('.choose:first').show();
            choose.find('.choose').attr("rowspan",choose.find('.choose').length);

            choose.find('.land:first').show();
            choose.find('.land').attr("rowspan",choose.find('.land').length);

            choose.find('.housing-exchange:first').show();
            choose.find('.housing-exchange').attr("rowspan",choose.find('.housing-exchange').length);

            choose.find('.housing-exchange-decorate:first').show();
            choose.find('.housing-exchange-decorate').attr("rowspan",choose.find('.housing-exchange-decorate').length);

            choose.find('.housing-currency:first').show();
            choose.find('.housing-currency').attr("rowspan",choose.find('.housing-currency').length);

            choose.find('.housing-currency-structure:first').show();
            choose.find('.housing-currency-structure').attr("rowspan",choose.find('.housing-currency-structure').length);

            choose.find('.housing-currency-decorate:first').show();
            choose.find('.housing-currency-decorate').attr("rowspan",choose.find('.housing-currency-decorate').length);

            choose.find('.housing-currency-disposable:first').show();
            choose.find('.housing-currency-disposable').attr("rowspan",choose.find('.housing-currency-disposable').length);

            choose.find('.not-exchange-price-difference:first').show();
            choose.find('.not-exchange-price-difference').attr("rowspan",choose.find('.not-exchange-price-difference').length);

        }

        /**
         * 更新界面
         * @param master
         */
        function updateHtml(result){

            console.log(result);

            total = 0.0;
            var dispose = methods.dispose(result);

            masterUpdate(result.master);
            var housing = dispose.overview.housing;
            housingOverviewUpdate(housing);
            landOverviewUpdate(dispose.overview.land);

            housingStructureInfoUpdate(dispose.detail.housing.structure);
            housingDecorateInfoUpdate(dispose.detail.housing.decorate);

            resettlementOverviewUpdate(dispose.overview.resettlement(housing.compensate));
            resettlementInfoUpdate(result.relocationTransition,housing.compensate);
            resettlementDifficultUpdate(result.master);

            $('#content .choose-room-settlement').html('');
            var compensate = $('#content .housing-total').attr('data-id');
            chooseHousingSettlementLand(
                result.land,
                (result.relocationTransition.currencyCompensateArea == undefined?0:result.relocationTransition.currencyCompensateArea/compensate).toFixed(2),
                (result.onTime==undefined?false:(result.onTime.signing&&result.onTime.seal))
            );
            var choose = dispose.exchange(
                result.housing,
                compensate-result.relocationTransition.currencyCompensateArea
            );
            chooseHousingSettlementHousingExchange(choose.housing);
            chooseHousingSettlementCurrency(choose.currency);

            chooseHousingSettlementReward(result.onTime,result.relocationTransition.arrange,compensate);
            chooseHousingSettlementNotExchangePriceDifference(choose.currency);

            chooseHousingSettlementStorefront(result.storefront);

            chooseHousingSettlementAppendages(result.appendages);

            var totalLayer = dispose.overview.totalLayer(result.housing);
            maxBuyArea = dispose.overview.maxBuyArea(compensate,totalLayer,result.homestead.area);

            chooseHousingSettlementStructureDifference(
                housing.structure,
                totalLayer,
                (compensate-result.relocationTransition.currencyCompensateArea),
                result.master.errorArea
            );
            chooseHousingSettlementBuyArea(result.master.buyArea);
            equallyShared(compensate);


            $('#content .choose-room-settlement').append('\
                        <tr>\
                            <td>合计</td>\
                            <td colspan=6 style="text-align: right;">'+total+'</td>\
                        </tr>\
                        ');

            merge();
        }

        $(document).ready(function () {

            $('.open').click(function () {

                var dialog = methods.household().dialog();
                layer.open({
                    title:'档案查询',
                    type: 1,
                    area: ['600px','auto'],
                    content: dialog.html,
                    btn:['查看','取消'],
                    success:function (layero, index) {
                        dialog.init(layero);
                    },
                    yes: function(index, layero){
                        var master = dialog.result();
                        if($.isEmptyObject(master)){
                            layer.msg("未查询到唯一的结果，请详细填写查询条件");
                        }else{
                            layer.close(index);
                            //加载层-默认风格
                            layer.load();
                            methods.result(master,function (result) {
                                layer.closeAll('loading');
                                updateHtml(result);
                                $('button').removeAttr('disabled');
                            });
                        }
                    }
                });
            });

            $('.relocation-transition').click(function () {

                var compensate = $('#content .housing-total').attr('data-id');

                var html = '\
                    <div class="ibox-content" style="overflow: hidden;height: 100%;">\
                        <form class="form-horizontal" method="post">\
                            <input type="text" name="masterId" style="display: none;">\
                            <div class="form-group">\
                                <label class="col-sm-2 control-label">安置方式</label>\
                                <div class="col-sm-10">\
                                    <label class="radio-inline i-checks"><input type="radio" value="1" name="way" checked>全部货币补偿</label>\
                                    <label class="radio-inline i-checks"><input type="radio" value="2" name="way">全部产权调换</label>\
                                    <label class="radio-inline i-checks"><input type="radio" value="3" name="way">两相结合</label>\
                                </div>\
                            </div>\
                            <div class="form-group">\
                                <label class="col-sm-2 control-label">过渡安置：</label>\
                                <div class="col-sm-10">\
                                    <div class="input-group m-b">\
                                        <span class="input-group-addon">货币补偿面积</span>\
                                        <input type="number" class="form-control" name="currencyCompensateArea">\
                                        <span class="input-group-addon">m² &nbsp;&nbsp; 发放6个月</span>\
                                    </div>\
                                    <div class="input-group m-b" disabled="">\
                                        <span class="input-group-addon">现房产权调换面积</span>\
                                        <input type="number" class="form-control" name="existingCompensateArea" disabled>\
                                        <span class="input-group-addon">m² &nbsp;&nbsp; 发放6个月</span>\
                                    </div>\
                                    <div class="input-group m-b" disabled>\
                                        <span class="input-group-addon">一期安置房面积</span>\
                                        <input type="number" class="form-control" name="firstPhaseCompensateArea" disabled>\
                                        <span class="input-group-addon" style="border-right: 0;border-left: 0">m² &nbsp;&nbsp; 发放</span>\
                                        <input type="number" class="form-control" name="firstPhaseTimeLimit" disabled>\
                                        <span class="input-group-addon">个月</span>\
                                    </div>\
                                    <div class="input-group m-b" disabled="">\
                                        <span class="input-group-addon">二期安置房面积</span>\
                                        <input type="number" class="form-control" name="secondPhaseCompensateArea" disabled>\
                                        <span class="input-group-addon" style="border-right: 0;border-left: 0">m² &nbsp;&nbsp; 发放</span>\
                                        <input type="number" class="form-control" name="secondPhaseTimeLimit" disabled>\
                                        <span class="input-group-addon">个月</span>\
                                    </div>\
                                    <div>\
                                        <div class="checkbox i-checks col-sm-6 ">\
                                            <label><input type="checkbox" value="1" name="arrange" > <i></i>安排临时周转房过渡</label>\
                                        </div>\
                                        <label class="control-label col-sm-6" style="padding-right: 0;">认定补偿安置总面积：'+compensate+' m²</label>\
                                    </div>\
                                </div>\
                            </div>\
                        </form>\
                    </div>';
                var masterId = $('#content .master').attr('data-id');
                methods.post('/api/relocationTransition/get',{masterId:masterId},function (result) {

                    layer.open({
                        type: 1,
                        area: ['600px','auto'],
                        content: html,
                        btn:['保存','取消'],
                        success:function (layero, index) {

                            function action(value){
                                $(layero).find('.input-group input').val('');

                                if(value == 1){
                                    $(layero).find('.input-group').attr('disabled',true);
                                    $(layero).find('.input-group input').attr('disabled',true);

                                    $(layero).find('input[name="currencyCompensateArea"]').attr('disabled',false);
                                    $(layero).find('input[name="currencyCompensateArea"]').parents('.input-group').attr('disabled',false);

                                    $(layero).find('input[name="currencyCompensateArea"]').val(compensate);
                                }else if(value ==2){
                                    $(layero).find('.input-group').attr('disabled',false);
                                    $(layero).find('.input-group input').attr('disabled',false);

                                    $(layero).find('input[name="currencyCompensateArea"]').attr('disabled',true);
                                    $(layero).find('input[name="currencyCompensateArea"]').parents('.input-group').attr('disabled',true);

                                    $(layero).find('input[name="existingCompensateArea"]').val(compensate);
                                }else{
                                    $(layero).find('.input-group').attr('disabled',false);
                                    $(layero).find('.input-group input').attr('disabled',false);

                                    $(layero).find('input[name="currencyCompensateArea"]').val(compensate);
                                }
                            }

                            if(result != null){

                                if(result.currencyCompensateArea == 0){
                                    action(2);
                                    $(layero).find('input[name="way"][value="2"]').attr('checked',true);
                                }else if(result.currencyCompensateArea == compensate){
                                    action(1);
                                    $(layero).find('input[name="way"][value="1"]').attr('checked',true);
                                }else{
                                    action(3);
                                    $(layero).find('input[name="way"][value="3"]').attr('checked',true);
                                }

                                $(layero).find('input[name="arrange"]').attr('checked',result.arrange);
                                $(layero).find('input[name="currencyCompensateArea"]').val(result.currencyCompensateArea);
                                $(layero).find('input[name="existingCompensateArea"]').val(result.existingCompensateArea);
                                $(layero).find('input[name="firstPhaseCompensateArea"]').val(result.firstPhaseCompensateArea);
                                $(layero).find('input[name="secondPhaseCompensateArea"]').val(result.secondPhaseCompensateArea);
                                $(layero).find('input[name="firstPhaseTimeLimit"]').val(result.firstPhaseTimeLimit);
                                $(layero).find('input[name="secondPhaseTimeLimit"]').val(result.secondPhaseTimeLimit);
                            }else{
                                $(layero).find('input[name="currencyCompensateArea"]').val(compensate);
                                $(layero).find('input[name="existingCompensateArea"]').val(0);
                                $(layero).find('input[name="firstPhaseCompensateArea"]').val(0);
                                $(layero).find('input[name="secondPhaseCompensateArea"]').val(0);
                            }
                            $(layero).find('input[name="masterId"]').val(masterId);

                            $(layero).find('.i-checks').iCheck({
                                checkboxClass: 'icheckbox_square-green',
                                radioClass: 'iradio_square-green',
                            });

                            $(layero).find('input[name="currencyCompensateArea"]').change(function () {
                                var remainder = compensate-$(this).val();
                                $(layero).find('input[name="existingCompensateArea"]').val(remainder);
                            });
                            $(layero).find('input[name="existingCompensateArea"]').change(function () {
                                var remainder = compensate
                                            -$(layero).find('input[name="currencyCompensateArea"]').val()
                                            -$(this).val();
                                $(layero).find('input[name="firstPhaseCompensateArea"]').val(remainder);
                            });
                            $(layero).find('input[name="firstPhaseCompensateArea"]').change(function () {
                                var remainder = compensate
                                            -$(layero).find('input[name="currencyCompensateArea"]').val()
                                            -$(layero).find('input[name="existingCompensateArea"]').val()
                                            -$(this).val();
                                $(layero).find('input[name="secondPhaseCompensateArea"]').val(remainder);
                            });
                            $(layero).find('input[name="firstPhaseTimeLimit"],input[name="secondPhaseTimeLimit"]').focus(function () {
                                $(this).parents('.input-group').removeClass('has-error');
                            });

                            $(layero).on('ifClicked','input[name="way"]', function () {
                                action($(this).val());
                            });
                        },
                        yes: function(index, layero){

                            var firstPhaseCompensateArea = $(layero).find('input[name="firstPhaseCompensateArea"]').val();
                            var secondPhaseCompensateArea = $(layero).find('input[name="secondPhaseCompensateArea"]').val();
                            var firstPhaseTimeLimit = $(layero).find('input[name="firstPhaseTimeLimit"]').val();
                            var secondPhaseTimeLimit = $(layero).find('input[name="secondPhaseTimeLimit"]').val();

                            var isSubmit = true;

                            if(firstPhaseCompensateArea != 0 && $.isEmptyObject(firstPhaseTimeLimit)){
                                $(layero).find('input[name="firstPhaseCompensateArea"]').parents('.input-group').addClass('has-error');
                                var isSubmit = false;
                            }
                            if(secondPhaseCompensateArea != 0 && $.isEmptyObject(secondPhaseTimeLimit)){
                                $(layero).find('input[name="secondPhaseCompensateArea"]').parents('.input-group').addClass('has-error');
                                var isSubmit = false;
                            }

                            if(isSubmit){
                                var options ={
                                    type: "post",
                                    url: "${path}/api/relocationTransition/save",
                                    dataType: "json",
                                    uploadProgress: function (event, position, total, percentComplete) {},
                                    success: function (result) {
                                        if (result.code == "${result_success}") {
                                            layer.close(index);
                                            layer.load();
                                            methods.result(result.data.master,function (result) {
                                                layer.closeAll('loading');
                                                updateHtml(result);
                                            });
                                        }else {
                                            layer.msg(result.data);
                                        }
                                    }
                                };

                                $(layero).find('form').ajaxSubmit(options);
                            }
                        }
                    });
                });
            });

            $('.time-reward').click(function () {
                var html = '\
                            <div class="ibox-content" style="overflow: hidden;height: 100%;">\
                                <form class="form-horizontal" method="post">\
                                    <input type="text" name="masterId" style="display: none;">\
                                    <div class="form-group">\
                                        <div class="col-sm-12">\
                                            <label class="checkbox-inline i-checks"><input type="checkbox" value="1" name="signing">按时签约</label>\
                                            <label class="checkbox-inline i-checks"><input type="checkbox" value="1" name="seal">按时封房</label>\
                                        </div>\
                                    </div>\
                                </form>\
                            </div>';
                var masterId = $('#content .master').attr('data-id');
                methods.post('/api/reward/get',{masterId:masterId},function (result) {

                    layer.open({
                        type: 1,
                        area: ['600px', 'auto'],
                        content: html,
                        btn: ['保存', '取消'],
                        success: function (layero, index) {
                            $(layero).find('input[name="masterId"]').val(masterId);

                            if(result != null){
                                $(layero).find('input[name="signing"]').attr('checked',result.signing);
                                $(layero).find('input[name="seal"]').attr('checked',result.seal);
                            }

                            $(layero).find('.i-checks').iCheck({
                                checkboxClass: 'icheckbox_square-green',
                                radioClass: 'iradio_square-green',
                            });
                        },
                        yes: function (index, layero) {
                            var options ={
                                type: "post",
                                url: "${path}/api/reward/save",
                                dataType: "json",
                                uploadProgress: function (event, position, total, percentComplete) {},
                                success: function (result) {
                                    if (result.code == "${result_success}") {
                                        layer.close(index);
                                        layer.load();
                                        methods.result(result.data.master,function (result) {
                                            layer.closeAll('loading');
                                            updateHtml(result);
                                        });
                                    }else {
                                        layer.msg(result.data);
                                    }
                                }
                            };

                            $(layero).find('form').ajaxSubmit(options);
                        }
                    });

                });
            });

            $('.disposable').click(function () {
                var html = '\
                            <div class="ibox-content" style="overflow: hidden;height: 100%;">\
                                <form class="form-horizontal" method="post">\
                                    <input type="text" name="masterId" style="display: none;">\
                                    <div class="form-group">\
                                        <label class="col-sm-6 control-label">一次性搬迁补助：</label>\
                                        <div class="col-sm-6">\
                                            <div class="input-group">\
                                                <input type="number" min="150" max="300" class="form-control" name="price"> <span class="input-group-addon">元/m²</span>\
                                            </div>\
                                        </div>\
                                    </div>\
                                </form>\
                            </div>';
                var masterId = $('#content .master').attr('data-id');
                methods.post('/api/household/find',{id:masterId},function (result) {

                    layer.open({
                        type: 1,
                        area: ['600px', 'auto'],
                        content: html,
                        btn: ['保存', '取消'],
                        success: function (layero, index) {
                            $(layero).find('input[name="masterId"]').val(masterId);

                            if(result != null){
                                $(layero).find('input[name="price"]').val(result.disposable);
                            }
                        },
                        yes: function (index, layero) {
                            var options ={
                                type: "post",
                                url: "${path}/api/household/set/disposable",
                                dataType: "json",
                                uploadProgress: function (event, position, total, percentComplete) {},
                                success: function (result) {
                                    if (result.code == "${result_success}") {
                                        layer.close(index);
                                        layer.load();
                                        methods.result(result.data,function (result) {
                                            layer.closeAll('loading');
                                            updateHtml(result);
                                        });
                                    }else {
                                        layer.msg(result.data);
                                    }
                                }
                            };

                            $(layero).find('form').ajaxSubmit(options);
                        }
                    });

                });

            });

            $('.storefront').click(function () {
                var html = '\
                            <div class="ibox-content" style="overflow: hidden;height: 100%;">\
                                <form class="form-horizontal" method="post">\
                                    <input type="text" name="id" style="display: none;">\
                                    <input type="text" name="masterId" style="display: none;">\
                                    <div class="form-group">\
                                        <label class="col-sm-2 control-label">店面面积：</label>\
                                        <div class="col-sm-10">\
                                            <div class="input-group">\
                                                <input type="number" class="form-control" name="area"> <span class="input-group-addon">m²</span>\
                                            </div>\
                                        </div>\
                                    </div>\
                                    <div class="form-group">\
                                        <label class="col-sm-2 control-label">认定：</label>\
                                        <div class="col-sm-10">\
                                            <select class="form-control" name="standardId">\
                                                <c:forEach items="${storefronts }" var="item">\
                                                <option value="${item.id}">${item.name }</option>\
                                                </c:forEach>\
                                            </select>\
                                        </div>\
                                    </div>\
                                </form>\
                            </div>';
                var masterId = $('#content .master').attr('data-id');
                methods.post('/api/identified/storefront/find',{masterId:masterId},function (result) {

                    layer.open({
                        type: 1,
                        area: ['600px', 'auto'],
                        content: html,
                        btn: ['保存', '取消'],
                        success: function (layero, index) {
                            $(layero).find('input[name="masterId"]').val(masterId);
                            if(result.content.length != 0){
                                var data = result.content[0];
                                $(layero).find('input[name="id"]').val(data.id);
                                $(layero).find('input[name="area"]').val(data.area);
                                $(layero).find('select[name="standardId"] option[value="'+data.standard.id+'"]').attr('selected',true);
                            }
                        },
                        yes: function (index, layero) {
                            var options ={
                                type: "post",
                                url: "${path}/api/identified/storefront/save",
                                dataType: "json",
                                uploadProgress: function (event, position, total, percentComplete) {},
                                success: function (result) {
                                    if (result.code == "${result_success}") {
                                        layer.close(index);
                                        layer.load();
                                        methods.result(result.data.master,function (result) {
                                            layer.closeAll('loading');
                                            updateHtml(result);
                                        });
                                    }else {
                                        layer.msg(result.data);
                                    }
                                }
                            };

                            $(layero).find('form').ajaxSubmit(options);
                        }
                    });

                });
            });

            $('.homestead').click(function () {
                var html = '\
                            <div class="ibox-content" style="overflow: hidden;height: 100%;">\
                                <form class="form-horizontal" method="post">\
                                    <input type="text" name="id" style="display: none;">\
                                    <input type="text" name="masterId" style="display: none;">\
                                    <div class="form-group">\
                                        <label class="col-sm-4 control-label">宅基地面积：</label>\
                                        <div class="col-sm-8">\
                                            <div class="input-group">\
                                                <input type="number" class="form-control" name="area"> <span class="input-group-addon">m²</span>\
                                            </div>\
                                        </div>\
                                    </div>\
                                </form>\
                            </div>';
                var masterId = $('#content .master').attr('data-id');
                methods.post('/api/identified/homestead/find',{masterId:masterId},function (result) {

                    layer.open({
                        type: 1,
                        area: ['600px', 'auto'],
                        content: html,
                        btn: ['保存', '取消'],
                        success: function (layero, index) {
                            $(layero).find('input[name="masterId"]').val(masterId);
                            if(result.content.length != 0){
                                var data = result.content[0];
                                $(layero).find('input[name="id"]').val(data.id);
                                $(layero).find('input[name="area"]').val(data.area);
                            }
                        },
                        yes: function (index, layero) {
                            var options ={
                                type: "post",
                                url: "${path}/api/identified/homestead/save",
                                dataType: "json",
                                uploadProgress: function (event, position, total, percentComplete) {},
                                success: function (result) {
                                    if (result.code == "${result_success}") {
                                        layer.close(index);
                                        layer.load();
                                        methods.result(result.data.master,function (result) {
                                            layer.closeAll('loading');
                                            updateHtml(result);
                                        });
                                    }else {
                                        layer.msg(result.data);
                                    }
                                }
                            };

                            $(layero).find('form').ajaxSubmit(options);
                        }
                    });

                });
            });

            $('.buyArea').click(function () {
                var html = '\
                            <div class="ibox-content" style="overflow: hidden;height: 100%;">\
                                <form class="form-horizontal" method="post">\
                                    <input type="text" name="masterId" style="display: none;">\
                                    <div class="form-group">\
                                        <label class="col-sm-6 control-label">照顾购买面积：</label>\
                                        <div class="col-sm-6">\
                                            <div class="input-group">\
                                                <input type="number" max="'+maxBuyArea+'" class="form-control" name="buyArea"> <span class="input-group-addon">m²</span>\
                                            </div>\
                                        </div>\
                                    </div>\
                                </form>\
                            </div>';
                var masterId = $('#content .master').attr('data-id');
                methods.post('/api/household/find',{id:masterId},function (result) {

                    layer.open({
                        type: 1,
                        area: ['600px', 'auto'],
                        content: html,
                        btn: ['保存', '取消'],
                        success: function (layero, index) {
                            $(layero).find('input[name="masterId"]').val(masterId);

                            if(result != null){
                                $(layero).find('input[name="buyArea"]').val(result.buyArea);
                            }
                        },
                        yes: function (index, layero) {
                            var options ={
                                type: "post",
                                url: "${path}/api/household/set/buyArea",
                                dataType: "json",
                                uploadProgress: function (event, position, total, percentComplete) {},
                                success: function (result) {
                                    if (result.code == "${result_success}") {
                                        layer.close(index);
                                        layer.load();
                                        methods.result(result.data,function (result) {
                                            layer.closeAll('loading');
                                            updateHtml(result);
                                        });
                                    }else {
                                        layer.msg(result.data);
                                    }
                                }
                            };

                            $(layero).find('form').ajaxSubmit(options);
                        }
                    });

                });

            });

            $('.errorArea').click(function () {
                var html = '\
                            <div class="ibox-content" style="overflow: hidden;height: 100%;">\
                                <form class="form-horizontal" method="post">\
                                    <input type="text" name="masterId" style="display: none;">\
                                    <div class="form-group">\
                                        <label class="col-sm-4 control-label">选房时误差面积：</label>\
                                        <div class="col-sm-8">\
                                            <div class="input-group">\
                                                <input type="number" class="form-control" name="errorArea"> <span class="input-group-addon">m²</span>\
                                            </div>\
                                        </div>\
                                    </div>\
                                </form>\
                            </div>';
                var masterId = $('#content .master').attr('data-id');
                methods.post('/api/household/find',{id:masterId},function (result) {

                    layer.open({
                        type: 1,
                        area: ['600px', 'auto'],
                        content: html,
                        btn: ['保存', '取消'],
                        success: function (layero, index) {
                            $(layero).find('input[name="masterId"]').val(masterId);

                            if(result != null){
                                $(layero).find('input[name="errorArea"]').val(result.errorArea);
                            }
                        },
                        yes: function (index, layero) {
                            var options ={
                                type: "post",
                                url: "${path}/api/household/set/errorArea",
                                dataType: "json",
                                uploadProgress: function (event, position, total, percentComplete) {},
                                success: function (result) {
                                    if (result.code == "${result_success}") {
                                        layer.close(index);
                                        layer.load();
                                        methods.result(result.data,function (result) {
                                            layer.closeAll('loading');
                                            updateHtml(result);
                                        });
                                    }else {
                                        layer.msg(result.data);
                                    }
                                }
                            };

                            $(layero).find('form').ajaxSubmit(options);
                        }
                    });

                });

            });
        });
    </script>

</body>

</html>
